﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Common.Utility;

namespace Resto.CostControl.Core.Domain.Model
{
    /// <summary>
    /// 半成品
    /// </summary>
    public partial class SemiMaterial : Material
    {      
        #region 构造函数

        internal SemiMaterial() {
            this.ID = IDHelper.CreateNewID();
        }

        #endregion


        #region 私有属性

        private IEntityRepository<SemiMaterial> _Repository;
        private IEntityRepository<SemiMaterial> Repository
        {
            get
            {
                if (_Repository == null)
                    _Repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<SemiMaterial, Material>();

                return _Repository;
            }
        }

        #endregion

        #region 业务方法

        internal override void Add()
        {
            Validate();

            CreatePrice();

            this.CreateAudit = new Audit();
            this.LastUpdateAudit = new Audit();

            this.Repository.Add(this);
        }

        internal override void Update()
        {
            Validate();

            CreatePrice();

            this.LastUpdateAudit = new Audit();

            this.Repository.Update(this);
        }

        internal override void Delete()
        {
            this.LastUpdateAudit = new Audit();

            this.IsDelete = true;
            this.Repository.Update(this);
        }

        internal void CreatePrice()
        {
            if (this.RawMaterial != null)
            {
                this.CurrentPrice = this.RawMaterial.CurrentPrice * this.ProcessRate;
            }
        }

        #endregion

       
    }
}
